package com.santiao.fuel.ui.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.santiao.fuel.R
import com.santiao.fuel.bean.GasSafetyGuideBean
import com.santiao.fuel.bean.SceienceItemData
import com.santiao.fuel.ui.adapter.GasSafetyGuideAdapter
import com.santiao.fuel.ui.adapter.base.ItemClickListener
import com.santiao.fuel.utils.DisplayUtil
import com.santiao.publics.ui.SettingFragment
import java.util.Collections

class GasSafetyGuide : AppCompatActivity() {


    companion object{
        fun comeGasSafetyGuideActivity(activity: Activity){
            activity.startActivity(Intent(activity ,GasSafetyGuide::class.java))

        }
    }



    var gas_safety_guide_data = mutableListOf<GasSafetyGuideBean>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_gas_safety_guide)

        DisplayUtil.initActionBar(this)
        initData();
        initView();

        SettingFragment.adLoad(1, null, findViewById(R.id.fl_content_1), this, this)
    }

    private fun initData() {
        Collections.addAll(gas_safety_guide_data ,
            GasSafetyGuideBean("燃气安全基础知识问题" , resources.getString(R.string.wz_1)),
            GasSafetyGuideBean("燃气设备的选择与安装" , resources.getString(R.string.wz_2)),
            GasSafetyGuideBean("燃气设备的使用和维护" , resources.getString(R.string.wz_3)),
            GasSafetyGuideBean("燃气泄漏的应急处理" , resources.getString(R.string.wz_4)),
            GasSafetyGuideBean( "燃气安全点检测" ,resources.getString(R.string.rq_anquanjiance)),
            GasSafetyGuideBean( "燃气设备故障排除" ,resources.getString(R.string.rq_shebeiguzhang)),
            GasSafetyGuideBean( "燃气使用中的节能技巧" ,resources.getString(R.string.wz_9)),
            GasSafetyGuideBean("燃气设备的正确清理方法" ,resources.getString(R.string.rq_clear)),
            )
    }


    /**
     * 可封装
     */
    private fun initView() {
        val gasBarRootView = findViewById<RelativeLayout>(R.id.gas_bar)
        val page_title = gasBarRootView.findViewById<TextView>(R.id.page_title)
        val page_back = gasBarRootView.findViewById<ImageView>(R.id.page_back)


        //设置沉浸式状态栏
        page_title.text = "安全指南"
        page_back.setOnClickListener {
            finish()
        }

        // 设置安全知识列表
        val gas_safety_guild_list = findViewById<RecyclerView>(R.id.gas_safety_guild_list)

        gas_safety_guild_list.layoutManager = LinearLayoutManager(this);
        gas_safety_guild_list.adapter = GasSafetyGuideAdapter(this , R.layout.gas_safety_item , gas_safety_guide_data)
        (gas_safety_guild_list.adapter as GasSafetyGuideAdapter).setItemClickListener(
            object : ItemClickListener<GasSafetyGuideBean> {
                override fun click(position: Int, data: GasSafetyGuideBean) {
                    val intent = Intent(baseContext, GasGuideDetails::class.java)
                    intent.putExtra(GasGuideDetails.PAGE_TITLE , data.title)
                    intent.putExtra(GasGuideDetails.PAGE_DESC , data.descipter)
                    startActivity(intent)
                }

            })



    }
}